package com.huiquan.analysis.constants;

import com.huiquan.management.service.AnalysisLabelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 语句模块用到的一些常量
 *
 * @author leo
 * @time 2017年4月19日 下午2:00:08
 */
@Component
public class AnalysisSentenceConstant {

    /**
     * 类型：1-主诉.
     */
    public static final int TYPE_ZS = 1;
    /**
     * 类型：2-现病史.
     */
    public static final int TYPE_XBS = 2;
    /**
     * 类型：3-医学影像.
     */
    public static final int TYPE_CT = 3;
    /**
     * 类型：4-诊断.
     */
    public static final int TYPE_DI = 4;

    /**
     * 现病史是否进行bme标注Flag:否
     */
    public static final int XBS_BME_FLAG_N = 0;
    /**
     * 现病史是否进行bme标注Flag:是
     */
    public static final int XBS_BME_FLAG_Y = 1;
    /**
     * 标注状态:未标注
     */
    public static final int LABEL_STATUS_UNLABELED = 0;
    /**
     * 标注状态:已标注
     */
    public static final int LABEL_STATUS_LABELED = 1;
    /**
     * 标注状态:半标注
     */
    public static final int LABEL_STATUS_SEMILABELED = 2;

    /**
     * 标注状态:已打包但未分配
     */
    public static final int LABEL_STATUS_SUBPACKAGED = 3;

    /**
     * 现病史来源类型：无.
     */
    public static final String XBS_SOURCE_TYPE_NULL = "unclassified";
    /**
     * 现病史来源类型：家族史.
     */
    public static final String XBS_SOURCE_TYPE_FAMILY_HIS = "family_history";
    /**
     * 现病史来源类型：个人史.
     */
    public static final String XBS_SOURCE_TYPE_PERSONAL_HIS = "personal_history";
    /**
     * 现病史来源类型：小既往史.
     */
    public static final String XBS_SOURCE_TYPE_SMALL_PAST_HIS = "small_past_history";
    /**
     * 现病史来源类型：体格检查信息.
     */
    public static final String XBS_SOURCE_TYPE_PHYSICAL_CHECK = "physical_check";
    /**
     * 现病史来源类型：器械检查（医学影像）.
     */
    public static final String XBS_SOURCE_TYPE_IMAGEOLOGY_INFO = "imageology_info";
    /**
     * 现病史来源类型：治疗.
     */
    public static final String XBS_SOURCE_TYPE_TREATMENT = "treatment";
    /**
     * 现病史来源类型：医嘱信息.
     */
    public static final String XBS_SOURCE_TYPE_DOCTOR_ADVICE_INFORMATION = "doctor_advice_information";

    /**
     * 现病史来源类型：实验室检查.
     */
    public static final String XBS_SOURCE_TYPE_LABORATORY_EXAMINATION = "laboratory_examination";

    /**
     * 现病史来源类型：辅助检查
     */
    public static final String XBS_SOURCE_TYPE_AUXILIARY_EXAMINATION = "auxiliary_examination";
    /**
     * 现病史来源类型：症状描述.
     */
    public static final String XBS_SOURCE_TYPE_SYMPTOMS_DESCRIBED = "symptoms_described";

    /**
     * 标签类型	 默认
     */
    public static final String DEFAULT_PROPERTY_LABEL = "DEFAULT_PROPERTY";
    /**
     * 标签类型	 体格检查
     */
    public static final String PHYSICAL_PROPERTY_LABEL = "PHYSICAL_PROPERTY";
    /**
     * 标签类型	 器械检查(医学影像)
     */
    public static final String IMAGEOLOGY_PROPERTY_LABEL = "IMAGEOLOGY_PROPERTY";
    /**
     * 标签类型	 个人史
     */
    public static final String PERSONAL_PROPERTY_LABEL = "PERSONAL_PROPERTY";
    /**
     * 标签类型	 词性
     */
    public static final String CHARACTER_LABEL = "CHARACTER";
    /**
     * 标签类型	 位置1
     */
    public static final String POSITION1_LABEL = "POSITION1";
    /**
     * 标签类型	 位置2
     */
    public static final String POSITION2_LABEL = "POSITION2";

    /**
     * 规则类型 现病史未归类
     */
    public static final int RULE_TYPE_XBS_NULL = 21;
    /**
     * 规则类型 现病史家族史
     */
    public static final int RULE_TYPE_XBS_FAMILY_HIS = 22;
    /**
     * 规则类型 现病史个人史
     */
    public static final int RULE_TYPE_XBS_PERSONAL_HIS = 23;
    /**
     * 规则类型 现病史体格检查信息
     */
    public static final int RULE_TYPE_XBS_PHYSICAL_CHECK = 24;
    /**
     * 规则类型 现病史器械检查
     */
    public static final int RULE_TYPE_XBS_IMAGEOLOGY_INFO = 25;

    /**
     * 规则类型 现病史 治疗
     */
    public static final int RULE_TYPE_XBS_TREATMENT = 26;
    /**
     * 规则类型 现病史医嘱信息
     */
    public static final int RULE_TYPE_XBS_DOCTOR_ADVICE_INFORMATION = 27;
    /**
     * 规则类型 实验室检查
     */
    public static final int RULE_TYPE_XBS_LABORATORY_EXAMINATION = 28;
    /**
     * 规则类型 现病史辅助检查
     */
    public static final int RULE_TYPE_XBS_AUXILIARY_EXAMINATION = 29;
    /**
     * 规则类型 现病史症状描述
     */
    public static final int RULE_TYPE_XBS_SYMPTOMS_DESCRIBED = 30;

    /**
     * 规则类型 现病史小既往史
     */
    public static final int RULE_TYPE_XBS_SMALL_PAST_HIS = 31;
    @Autowired
    private AnalysisLabelService analysisLabelService;


    private static AnalysisSentenceConstant getListUtil;

    @PostConstruct
    public void getListUtil() {
        getListUtil = this;
        getListUtil.analysisLabelService = this.analysisLabelService;
    }

    public static final Map<String, String> XBS_SOURCE_TYPE_SIMPLE_TITLE = new LinkedHashMap<>();

    static {
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_NULL, "无分类");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_FAMILY_HIS, "家族");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_PERSONAL_HIS, "个人");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_SMALL_PAST_HIS, "小既往史");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_PHYSICAL_CHECK, "体格");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_IMAGEOLOGY_INFO, "器械");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_TREATMENT, "治疗");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_DOCTOR_ADVICE_INFORMATION, "医嘱");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_LABORATORY_EXAMINATION, "实验室检查");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_AUXILIARY_EXAMINATION, "辅助检查");
        XBS_SOURCE_TYPE_SIMPLE_TITLE.put(XBS_SOURCE_TYPE_SYMPTOMS_DESCRIBED, "症状描述");
    }

    public static final Map<String, String> XBS_SOURCE_TYPE_PRE_LABEL_TYPE = new LinkedHashMap<>();

    static {
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_NULL, "21");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_FAMILY_HIS, "22");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_PERSONAL_HIS, "23");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_SMALL_PAST_HIS, "24");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_IMAGEOLOGY_INFO, "25");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_PHYSICAL_CHECK, "26");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_TREATMENT, "27");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_DOCTOR_ADVICE_INFORMATION, "28");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_LABORATORY_EXAMINATION, "29");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_AUXILIARY_EXAMINATION, "30");
        XBS_SOURCE_TYPE_PRE_LABEL_TYPE.put(XBS_SOURCE_TYPE_SYMPTOMS_DESCRIBED, "31");
    }

    public static final Map<String, String> secondTypeMap = new LinkedHashMap<>();

    static {

        secondTypeMap.put(XBS_SOURCE_TYPE_IMAGEOLOGY_INFO, "器械检查");
        secondTypeMap.put(XBS_SOURCE_TYPE_NULL, "未分类");
        secondTypeMap.put(XBS_SOURCE_TYPE_FAMILY_HIS, "家族史");
        secondTypeMap.put(XBS_SOURCE_TYPE_SMALL_PAST_HIS, "小既往史");
        secondTypeMap.put(XBS_SOURCE_TYPE_PHYSICAL_CHECK, "体格检查");
        secondTypeMap.put(XBS_SOURCE_TYPE_PERSONAL_HIS, "个人史");
        secondTypeMap.put(XBS_SOURCE_TYPE_TREATMENT, "治疗");
        secondTypeMap.put(XBS_SOURCE_TYPE_DOCTOR_ADVICE_INFORMATION, "医嘱信息");
        secondTypeMap.put(XBS_SOURCE_TYPE_LABORATORY_EXAMINATION, "实验室检查");
        secondTypeMap.put(XBS_SOURCE_TYPE_AUXILIARY_EXAMINATION, "辅助检查");
        secondTypeMap.put(XBS_SOURCE_TYPE_SYMPTOMS_DESCRIBED, "症状描述");
    }

    public static final Map<String, Integer> xbsRuleTypeMap = new HashMap<>();

    static {
        xbsRuleTypeMap.put("unclassified", RULE_TYPE_XBS_NULL);
        xbsRuleTypeMap.put("family_history", RULE_TYPE_XBS_FAMILY_HIS);
        xbsRuleTypeMap.put("personal_history", RULE_TYPE_XBS_PERSONAL_HIS);
        xbsRuleTypeMap.put("small_past_history", RULE_TYPE_XBS_SMALL_PAST_HIS);
        xbsRuleTypeMap.put("physical_check", RULE_TYPE_XBS_PHYSICAL_CHECK);
        xbsRuleTypeMap.put("imageology_info", RULE_TYPE_XBS_IMAGEOLOGY_INFO);
        xbsRuleTypeMap.put("treatment", RULE_TYPE_XBS_TREATMENT);
        xbsRuleTypeMap.put("doctor_advice_information", RULE_TYPE_XBS_DOCTOR_ADVICE_INFORMATION);
        xbsRuleTypeMap.put("laboratory_examination", RULE_TYPE_XBS_LABORATORY_EXAMINATION);
        xbsRuleTypeMap.put("auxiliary_examination", RULE_TYPE_XBS_AUXILIARY_EXAMINATION);
        xbsRuleTypeMap.put("symptoms_described", RULE_TYPE_XBS_SYMPTOMS_DESCRIBED);
    }

    public static final LinkedHashMap<String, String> getPropertyMapByTypeAndSecondType(int type, String secondType) {
        LinkedHashMap<String, String> propertyMap = new LinkedHashMap<>();
        // 现病史分类

        if (type == AnalysisSentenceConstant.TYPE_XBS) {
            // 个人史
            if (StringUtils.equalsIgnoreCase(AnalysisSentenceConstant.XBS_SOURCE_TYPE_PERSONAL_HIS, secondType)) {
                propertyMap = getListUtil.analysisLabelService.getPropertyMap("PERSONAL_PROPERTY");
            } else if (StringUtils.equalsIgnoreCase(AnalysisSentenceConstant.XBS_SOURCE_TYPE_IMAGEOLOGY_INFO,
                    secondType)) {
                propertyMap = getListUtil.analysisLabelService.getPropertyMap("IMAGEOLOGY_PROPERTY");
            } else {
                propertyMap = getListUtil.analysisLabelService.getPropertyMap("DEFAULT_PROPERTY");
            }
            // 默认分类
        } else {
            propertyMap = getListUtil.analysisLabelService.getPropertyMap("DEFAULT_PROPERTY");
        }
        return propertyMap;
    }

    public static final LinkedHashMap<String, String> getPropertyMapByType(String type) {
        return getListUtil.analysisLabelService.getPropertyMap(type);
    }

    public static final ArrayList<String> getPositionByType(String type) {
        return getListUtil.analysisLabelService.getPositionMap(type);
    }

}
